home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-16 | 3.8 KB | 234 lines | [TEXT/KAHL] |
- /*****
- * GeneralUtilities.c
- *
- * Routines di utilità generale.
- * © Com&Media, 1994
- *
- * 15/10/94 Scorporo da Utilities.h (Fabio Barbieri)
- * 18/8/94 Prima stesura (Fabio Barbieri)
- *
- *
- *****/
-
-
- /***** Include standard *****/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <limits.h>
- #include <Events.h>
- #include <Fonts.h>
- #include <Memory.h>
- #include <TextUtils.h>
-
- /***** Include locali *****/
- #include "GeneralUtilities.h"
-
- /***** Define macro *****/
-
- /***** Define valori *****/
-
- #pragma segment GeneralUtilities
-
- /***** Typedef globali *****/
-
- /***** Funzioni esterne *****/
-
- /***** Variabili esterne *****/
-
- /***** Variabili globali *****/
-
- /***** Statiche globali *****/
-
- /***** Function prototyping *****/
-
-
- /****
- * Wait(howMuch)
- *
- * Attende <howMuch> sessantesimi di secondo.
- *
- ****/
-
- void Wait(short howMuch)
- {
- long stopTime = TickCount() + (long)howMuch;
- while(TickCount() <= stopTime);
- }
- /* end Wait */
-
- #ifdef PIPPO
- /****
- * FixedToFloat(valFixed, valFloat)
- *
- * Converte il valore Fixed <valFixed> nel valore float <valFloat>.
- *
- ****/
-
- void FixedToFloat(Fixed valFixed, float *valFloat)
- {
- short parteInt, i;
- unsigned long mask;
- float valoreBit, parteFrac;
-
- parteInt = HiWord(valFixed);
-
- valoreBit = 0.5;
- mask = 0x8000L;
- parteFrac = 0.0;
- for(i = 0; i < 16; i++)
- {
- if(valFixed & mask)
- parteFrac += valoreBit;
- mask = mask >> 1;
- valoreBit *= 0.5;
- }
- *valFloat = parteFrac + (float)parteInt;
- }
- /* end FixedToFloat */
-
-
- /****
- * FloatToFixed(valFloat, valFixed)
- *
- * Converte il valore float <valFloat> nel valore Fixed <valFixed>.
- *
- ****/
-
- void FloatToFixed(float valFloat, Fixed *valFixed)
- {
- char buffer[256], *pFrac;
- short parteInt, parteFrac, divisore, i;
-
- divisore = 10000;
- sprintf(buffer, "%.4f", valFloat);
- for(i = 0; buffer[i] != '.'; i++)
- if(buffer[i] == '\0')
- break;
- if(buffer[i] == '\0')
- parteFrac = 0;
- else
- {
- pFrac = &buffer[i+1];
- parteFrac = atoi(pFrac);
- }
-
- buffer[i] = '\0';
- parteInt = atoi(buffer);
- *valFixed = (((long)parteInt) << 16) | FixRatio(parteFrac, divisore);
- }
- /* end FloatToFixed */
- #endif
-
- /****
- * GetFontNumber(fontName, fontNum)
- *
- * Ricerca la font di nome <fontName> tra quelle presenti nel sistema; se la trova, ne pone l'id
- * in <fontNum> e torna true, altrimenti pone <fontNum> a 0 e torna false.
- *
- ****/
-
- Boolean GetFontNumber(Str255 fontName, short *fontNum)
- {
- Str255 systemFontName;
-
- GetFNum(fontName, fontNum);
- if(*fontNum == 0)
- {
- GetFontName(0, systemFontName);
- return(EqualString(fontName, systemFontName, false, false));
- }
- else
- return(true);
- }
- /* end GetFontNumber */
-
-
- /****
- * CompHandle(hdl1, hdl2)
- *
- * Confronta il contenuto degli handle <hdl1> e <hdl2>: torna true se sono identici,
- * false altrimenti.
- *
- ****/
-
- Boolean CompHandle(Handle hdl1, Handle hdl2)
- {
- short len;
- short val;
-
- if(hdl1 || hdl2)
- {
- if(hdl1 == nil || hdl2 == nil)
- return(false);
-
- len = GetHandleSize(hdl1);
- if(len != GetHandleSize(hdl2))
- return(false);
-
- HLock(hdl1);
- HLock(hdl2);
- val = memcmp(*hdl1, *hdl2, len);
- HUnlock(hdl1);
- HUnlock(hdl2);
- return(val == 0);
- }
- return(true);
- }
- /* end CompHandle */
-
-
- /****
- * CicloAttesa(void)
- *
- * Richiama WaitNextEvent per non bloccare le altre applicazioni.
- *
- ****/
-
- void CicloAttesa(void)
- {
- EventRecord event;
-
- WaitNextEvent(everyEvent, &event, LONG_MAX, nil);
- }
- /* end CicloAttesa */
-
- /***
- *
- * get the lower byte of a short.
- *
- ****/
- short getLow(short value)
- {
- return(value & 0xFF);
- }
- /* end getLow */
-
- /***
- *
- * get the lower byte of a short.
- *
- ****/
- short getHi(short value)
- {
- short val = value & 0xFF00;
-
- return(val >> 8);
- }
- /* end getHi */
-
- /***
- *
- * merge the high and low part of a short.
- *
- ***/
- short merge(short hi, short low)
- {
- short val = hi & 0xFF;
-
- val = val << 8;
- return(val | (low & 0xFF));
- }
- /* end merge */
-